<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head>
	<link rel="shortcut icon" href="favicon.ico">
	<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
	<link th:href="@{/css/layui.css}" rel="stylesheet" >
	<link th:href="@{/css/font-awesome.css}" rel="stylesheet"/>
	<!-- bootstrap-table 表格插件样式 -->
	<link th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>
	<link th:href="@{/ajax/libs/jqTreeGrid/jquery.treegrid.css}" rel="stylesheet"/>
	<link th:href="@{/css/animate.css}" rel="stylesheet"/>
	<link th:href="@{/css/style.css}" rel="stylesheet"/>
	<link th:href="@{/css/checkbox.css}" rel="stylesheet"/>
	<link th:href="@{/ajax/libs/select/select2.css}" rel="stylesheet"/>
	<link th:href="@{/ruoyi/css/ry-ui.min.css}" rel="stylesheet"/>
	<link href="/ajax/libs/iCheck/custom.css" th:href="@{/ajax/libs/iCheck/custom.css}" rel="stylesheet"/>
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-user-edit">
			<input name="userId"  type="hidden"  />
			<input name="deptId"  type="hidden"  id="treeId" th:value="${user.dept.id}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label ">职工编号：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="id" id="id" readonly="true" th:value="${user.id}" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">部门名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" th:value="${user.dept.name}" name="deptName" onclick="selectDeptTree()" readonly="true" id="treeName" >
				</div>
			</div>
			<div class="form-group">
			<label class="col-sm-3 control-label">姓名：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" name="realName" id="realName"  th:value="${user.realName}">
			</div>
		</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">性别：</label>
				<div class="col-sm-8">
					<select id="sex" class="form-control m-b">
						<div th:if="${user.sex} eq '男'"><option selected="selected">男</option><option >女</option></div>
						<div th:if="${user.sex} eq '女'"><option selected="selected">女</option><option >男</option></div>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">籍贯：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="address" id="address"  th:value="${user.address}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label ">职工邮箱：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="email" id="email" th:value="${user.email}" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<select id="status" class="form-control m-b" name="id">
						<div th:if="${user.status} eq 1"><option selected="selected" >在职</option><option >离职</option></div>
						<div th:if="${user.status} eq 2"><option selected="selected" >离职</option><option >在职</option></div>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">岗位：</label>
				<div class="col-sm-8">
					<select id="parentRole" name="parentRole" class="form-control select2">
						<option th:each="roleitem:${roleList}" th:value="${roleitem.roleId}" th:text="${roleitem.roleDescription}" th:selected="${roleitem.roleId eq user.roleList.get(0).roleId}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="button" onclick="edit()" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
	</div>
	<script th:src="@{/js/jquery.min.js}"></script>
	<script th:src="@{/js/bootstrap.min.js}"></script>
	<!-- bootstrap-table 表格插件 -->
	<script th:src="@{/ajax/libs/bootstrap-table/bootstrap-table.min.js}"></script>
	<script th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
	<script th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js}"></script>
	<script th:src="@{/ajax/libs/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.min.js}"></script>
	<!-- Data Tables -->
	<script th:src="@{/js/plugins/dataTables/jquery.dataTables.js}"></script>
	<script th:src="@{/js/plugins/dataTables/dataTables.bootstrap.js}"></script>
	<script th:src="@{/js/plugins/jeditable/jquery.jeditable.js}"></script>
	<script th:src="@{/js/plugins/layer/laydate/laydate.js}"></script>
	<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
	<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
	<script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
	<script th:src="@{/ajax/libs/layui/layui.js}"></script>
	<script th:src="@{/ruoyi/js/common.js?v=2.2.0}"></script>
	<script th:src="@{/ruoyi/js/yuyu-ui.min.js?v=2.2.0}"></script>
	<script th:src="@{/ajax/libs/iCheck/icheck.min.js}"></script>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
	<script>
        function edit() {
            var deptId = $("input[name='deptId']").val();
        	var id = $("input[name='id']").val();
        	var realName = $("input[name='realName']").val();
            var email = $("input[name='email']").val();
            var address = $("input[name='address']").val();
        	var sex = $("#sex option:selected").val();
            var status =  $("#status option:selected").val() == "在职" ? 1 : 2;
            var roleId =  $("#parentRole option:selected").val();
            var json = {
                "deptId" : deptId,
                "id" : id,
				"realName": realName,
				 "email":   email,
                "address" : address,
                "sex": sex,
                "status" : status
            };
        	$.ajax({
        		cache : true,
        		type : "post",
        		url : "/user/editpost/"+roleId,
				data: JSON.stringify(json),
                dataType:'json',
                contentType:"application/json",
        		async : false,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        		    if (data.code==200){
						parent.layer.msg('编辑成功', {icon: 1});
                        setTimeout(function () {
                              parent.refreshTable();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                        },500);
                    }
        		}
        	});
        }
        /*用户管理-修改-选择部门树*/
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = treeId == null || treeId == "" ? "100" : treeId;
            var url = "/system/dept/selectDeptTree/" ;
            $.modal.open("选择部门", url, '380', '380');
        }
    </script>
</body>
</html>
